package cn.edu.neusoft.wuguangsheng.flowerimpression.activity;

import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import java.util.List;

import cn.edu.neusoft.wuguangsheng.flowerimpression.R;
import cn.edu.neusoft.wuguangsheng.flowerimpression.adapter.UserOrderInfoAdapter;
import cn.edu.neusoft.wuguangsheng.flowerimpression.bean.UserOrderBean;
import cn.edu.neusoft.wuguangsheng.flowerimpression.bean.UserOrderGoodsBean;
import cn.edu.neusoft.wuguangsheng.flowerimpression.listener.TListener;
import cn.edu.neusoft.wuguangsheng.flowerimpression.model.GetUserOrderInfoModel;

public class OrderInfoActivity extends BaseActivity {
    ImageView orderinfo_fh;
    TextView orderinfo_username,orderinfo_userphone,orderinfo_address;
    TextView orderinfo_ordernumber,orderinfo_xdsj,orderinfo_flag,orderinfo_shopname;
    TextView orderinfo_allprice,orderinfo_allnum;
    RecyclerView orderinfo_rv;

    private String orderid;
    private List<UserOrderGoodsBean> items;
    @Override
    void initView() {
        setLayout_file(R.layout.activity_order_info);
        orderid = getIntent().getStringExtra("orderid");
        orderinfo_fh = (ImageView)findViewById(R.id.orderinfo_fh);
        orderinfo_username = (TextView)findViewById(R.id.orderinfo_username);
        orderinfo_userphone = (TextView)findViewById(R.id.orderinfo_userphone);
        orderinfo_address = (TextView)findViewById(R.id.orderinfo_address);
        orderinfo_ordernumber = (TextView)findViewById(R.id.orderinfo_ordernumber);
        orderinfo_xdsj = (TextView)findViewById(R.id.orderinfo_xdsj);
        orderinfo_flag = (TextView)findViewById(R.id.orderinfo_flag);
        orderinfo_shopname = (TextView)findViewById(R.id.orderinfo_shopname);
        orderinfo_rv = (RecyclerView)findViewById(R.id.orderinfo_rv);
        orderinfo_allprice = (TextView)findViewById(R.id.orderinfo_allprice);
        orderinfo_allnum = (TextView)findViewById(R.id.orderinfo_allnum);

    }

    @Override
    void initEvent() {
        orderinfo_fh.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

    }

    @Override
    void initDate() {
        GetUserOrderInfoModel getUserOrderInfoModel = new GetUserOrderInfoModel();
        getUserOrderInfoModel.getUserOrderInfo(orderid, new TListener<UserOrderBean>() {
            @Override
            public void onResponse(UserOrderBean userOrderBean) {
                items = userOrderBean.getOrder_goods();
                orderinfo_address.setText(userOrderBean.getOrder_address());
                orderinfo_username.setText(userOrderBean.getUseraddress_username());
                orderinfo_userphone.setText(userOrderBean.getUseraddress_phone());
                orderinfo_ordernumber.setText(userOrderBean.getOrder_number());
                orderinfo_xdsj.setText(userOrderBean.getOrder_time());
                orderinfo_shopname.setText(userOrderBean.getShop_name());
                orderinfo_allprice.setText("共支付"+String.valueOf(userOrderBean.getOrder_allprice())+"元");
                orderinfo_allnum.setText("共"+userOrderBean.getOrder_goodsnum()+"件");
                String flag = userOrderBean.getOrder_flag();

                if (flag.equals("0")){
                    orderinfo_flag.setText("等待付款");
                }
                else if (flag.equals("1")){
                    orderinfo_flag.setText("等待发货");
                }
                else if (flag.equals("2")){
                    orderinfo_flag.setText("等待收货");
                }
                else if (flag.equals("3")){
                    orderinfo_flag.setText("已收货");
                }
                else {
                    orderinfo_flag.setText("订单异常");
                }

                LinearLayoutManager linearLayoutManager=new LinearLayoutManager(OrderInfoActivity.this);
                linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
                orderinfo_rv.setLayoutManager(linearLayoutManager);

                UserOrderInfoAdapter userOrderInfoAdapter=new UserOrderInfoAdapter(OrderInfoActivity.this,items,R.layout.userordergoods_item);
                orderinfo_rv.setAdapter(userOrderInfoAdapter);
                orderinfo_rv.setItemAnimator(new DefaultItemAnimator());
               // Toast.makeText(OrderInfoActivity.this,"1",Toast.LENGTH_LONG).show();
            }

            @Override
            public void onFail(String msg) {
                Toast.makeText(OrderInfoActivity.this,"0",Toast.LENGTH_LONG).show();
            }
        });
    }
}
